﻿using MongoDB.Driver;
using Sustainalytics.Entities.RiskRatings;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.ScreeningTool.Synchronization.Handlers.RiskRatings
{
    public class EventIndicatorHandler : IHandlerWithGrouping<EventIndicator>
    {
        public ProjectionDefinition<EventIndicator> GetProjection(ProjectionDefinitionBuilder<EventIndicator> builder) => builder
            .Include(x => x.Name)
            .Include(x => x.EventJustification)
            .Include(x => x.OutlookComments)
            .Include(x => x.Outlook)
            .Include(x => x.OutlookText)
            .Include(x => x.ControversySummary)
            .Include(x => x.EventCategoryText);

        public IEnumerable<ExtraElement> GetExtraElements(IEnumerable<EventIndicator> entities)
            => entities.SelectMany(entity => new ExtraElementList
            {
                { $"{entity.Name}-Answer Category Justification-RR", entity.EventJustification                },
                { $"{entity.Name}-Outlook Comments-RR",              entity.OutlookComments.JoinStrings("  ") },
                { $"{entity.Name}-Outlook Score-RR",                 entity.Outlook                           },
                { $"{entity.Name}-Outlook Category-RR",              entity.OutlookText                       },
                { $"{entity.Name}-Summary-RR",                       entity.ControversySummary                },
                { $"{entity.Name}-Category-RR",                      entity.EventCategoryText                 },
            });
    }
}
